# -*- coding: utf-8 -*-
# created on 2017/3/1

from mathsolver.functions.base import *
from sympy.abc import x, y
from mathsolver.functions.mathematica.mathematicaSolve import MathematicaSolve


# 已知平行四边形三个点，求第四个点
class PingXingShiBianXingFourthPoint(BaseFunction):
    def solver(self, *args):
        point_a, point_b, point_c = args[0].objs
        point_a_name = point_a.name
        point_a_value = point_a.sympify()
        point_b_name = point_b.name
        point_b_value = point_b.sympify()
        point_c_name = point_c.name
        point_c_value = point_c.sympify()
        point_d_name = str('D')
        point_d_value = [x, y]
        self.steps.append(["", "设%s为(%s, %s), 则" % (point_d_name, point_d_value[0], point_d_value[1])])
        vector_ab_name = "\\overrightarrow{%s}" % (point_a_name + point_b_name)
        vector_dc_name = "\\overrightarrow{%s}" % (point_d_name + point_c_name)
        vector_ab_value = (point_b_value[0] - point_a_value[0], point_b_value[1] - point_a_value[1])
        vercor_dc_value = (point_c_value[0] - point_d_value[0], point_c_value[1] - point_d_value[1])
        self.steps.append(["", "%s = %s" % (new_latex(vector_ab_name), new_latex(vector_dc_name))])
        eqs = [[vector_ab_value[0], vercor_dc_value[0]], [vector_ab_value[1], vercor_dc_value[1]]]
        self.steps.append(["", "%s" % (BaseEqs(eqs).printing())])
        stepsolver = MathematicaSolve().solver(BaseEqs(eqs))
        answer = stepsolver.output[0].sympify()
        for keys, values in answer.items():
            for value in values:
                new_answer = zip(keys, value)
        for item in new_answer:
            if item[0] == x:
                x_value = item[1]
            else:
                y_value = item[1]
        new_point_d_value = [x_value, y_value]
        self.steps.append(["", "∴%s" % (BasePoint({"name": point_d_name, "value": new_point_d_value}).printing())])
        self.output.append(BasePoint({"name": point_d_name, "value": new_point_d_value}))
        self.label.add("平面向量坐标运算-平行四边形")
        return self


if __name__ == '__main__':
    pass
